package com.bizfty.apiexecutor;

import com.bizfty.apiexecutor.classloader.ExecutorClassLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.context.support.StandardServletEnvironment;

public class ServletInitializer extends SpringBootServletInitializer {

    private static final Logger logger = LoggerFactory.getLogger(ServletInitializer.class);

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        ConfigurableEnvironment environment = new StandardServletEnvironment();
        application.environment(environment);
        String path = environment.getProperty("deploy.path");
        if(path==null){
            path = Application.deployPath;
        }
        Application.executorClassLoader = new ExecutorClassLoader(path);
        ResourceLoader rl = new DefaultResourceLoader(Application.executorClassLoader);
        application.resourceLoader(rl);
        return application.sources(Application.class);
    }

}
